@extends('common.base-master')

@section('html-head')
    <link href="{{url('css/facilitatorcenter.css')}}" type="text/css" rel="stylesheet"/>
    <script src="{{url('js/lib/area.js')}}"></script>
    <script src="{{url('js/lib/area2.js')}}"></script>
    <script src="{{url('js/facilitatorcenter.js')}}"></script>
    <link href="{{url('css/autoMail.css')}}" type="text/css" rel="stylesheet"/>
    <script src="{{url('/js/lib/autoMail.js')}}"></script>
@endsection

@section('html-body')
    <main>
        <div>
            <section class="sidebar">
                <div>
                    <dl>
                        <dt><a href="javascript:void(0)"><img id="photo_id" src="{{route('Api.Photo.Show',['id'=>$user->id])}}" /></a><button id="inputImage">修改头像</button></dt>
                        <dd>{{$user->getDisplayName()}}</dd>
                    </dl>
                </div>
                <div>
                    <ul>
                        <li class="b_1 selected">基本信息</li>
                        <li class="b_2">消息通知</li>
                        <li class="b_3">我是服务商</li>
                        <li class="b_4">我是推广员</li>
                    </ul>
                    <a href="{{route('Home.Service.signOut')}}" class="b_5">退出</a>
                </div>
            </section>
            <section class="module">
                <div class="chunks c_1">
                    <div>
                        <p class="point">Hi，<em>{{$user->getDisplayName()}}</em>，请如实填写以下内容，这是我们联系您的方式</p>
                    </div>
                    <div class="makeOut">
                        <form id="user_info">
                        <ul>
                            <input type="hidden" name="state" value="1" />
                            @if($facInfo->state == 1)<li style="color: red">【审核中不可修改】</li>@endif
                            <li class="nickName"><em class="prompt">*</em><em>Wike昵称</em><input type="text" name="nickname" value="{{$facInfo->nickname}}" @if($facInfo->state == 1)disabled @endif/><em class="nickName_error error"></em></li>
                            <li class="realName"><em class="prompt">*</em><em>真实姓名</em><input type="text" name="realname" value="{{$facInfo->realname}}" @if($facInfo->state == 1)disabled @endif/><em class="realName_error error"></em></li>
                            <li class="area">
                                <em class="prompt">*</em><em>所在地区</em>
                                <div class="distruct">
                                    <select id="s_province" name="s_province" @if($facInfo->state == 1)disabled @endif></select>  
                                    <select id="s_city" name="s_city" @if($facInfo->state == 1)disabled @endif></select>  
                                    <select id="s_county" name="s_county" @if($facInfo->state == 1)disabled @endif></select>
                                    @if($facInfo->province && $facInfo->city && $facInfo->area)<script>opt0 = ["{{$facInfo->province}}","{{$facInfo->city}}","{{$facInfo->area}}"]</script>@endif
                                    <script type="text/javascript">_init_area();</script>
                                </div>
                                <div id="show"></div>
                            </li>
                            <li class="contact"><em class="prompt">*</em><em>联系电话</em><input type="text" name="telephone" value="{{$facInfo->telephone}}" @if($facInfo->state == 1)disabled @endif/><em class="contact_error error"></em></li>
                            <li class="qq" class="contact_error error"><em class="prompt">*</em><em>联系QQ</em><input type="text" name="qq" value="{{$facInfo->qq}}" @if($facInfo->state == 1)disabled @endif/><em class="qq_error error"></em></li>
                            <li class="email"><em class="prompt">*</em><em>联系邮箱</em><input type="text" id="email" name="email" value="{{$facInfo->email}}" @if($facInfo->state == 1)disabled @endif/><em class="email_error error"></em></li>
                            <li><input type="hidden" name="state" value="1" /><button class="save" @if($orgInfo && $orgInfo->state == 1)disabled @endif>保存</button></li>
                        </ul>
                        </form>
                    </div>
                </div>
                <!--消息通知-->
                <div class="chunks c_2"  style="display:none;">
                    <div class="message">
                        <ul>
                            @if(count($msgs) !== 0)
                                @foreach($msgs as $msg)
                            <li>
                                <time>{{$msg->create_at}}</time>
                                <dl>
                                    <dt>[Wike官方消息]</dt>
                                    <dd>{{$msg->system_msg}}</dd>
                                </dl>
                            </li>
                                @endforeach
                                @else
                                暂时无消息
                            @endif
                        </ul>
                    </div>
                </div>

                <!--我是服务商-->
                <div class="chunks c_3" style="display:none;">
                    <div class="authentication" @if(!$orgInfo)style="display: block;" @elseif($orgInfo && $orgInfo->state == '0') style="display: block;" @else style="display: none;" @endif>
                        <p>您还没有进行服务商认证哦，赶紧认证吧~</p>
                        <button id="goFac">现在认证</button>
                    </div>
                    <div class="facilitator" @if(!$orgInfo || ($orgInfo && $orgInfo->state == '0'))style="display: none;" @else style="display: block;" @endif>
                        <ul class="f_nav">
                            <li class="selected">团队管理</li>
                            <li>案例管理</li>
                        </ul>
                        <!--团队管理-->
                        <div class="team" style="display: block">
                            <form id="org_info">
                            <ul>
                                <input type="hidden" name="state" value="1" />
                                @if($orgInfo && $orgInfo->state == 1)<li style="color: red">【审核中不可修改】</li>@endif
                                <li class="upload">
                                    <em>上传标志</em>
                                    <div class="inline">
                                        <dl>
                                            <dt><a href="javascript:void(0);" id="uplogo"><img id="logo_img" src="{{route('Api.OrgPhoto.Show',['id'=>$user->id])}}" style="width: 65px;height: 65px" /></a></dt>
                                            <dd></dd>
                                        </dl>
                                    </div>
                                </li>
                                <li class="serves_type">
                                    <em>服务性质</em>
                                    <div class="inline">
                                        <p><input type="radio" name="type" class="personal" data-type="0" value="0" @if($orgInfo && $orgInfo->org_type == 0) checked @endif @if($orgInfo && $orgInfo->state == 1)disabled @endif/>个人</p>
                                        <p><input type="radio" name="type" data-type="1" value="1" @if($orgInfo && $orgInfo->org_type == 1) checked @endif @if($orgInfo && $orgInfo->state == 1)disabled @endif/>工作窒</p>
                                        <p><input type="radio" name="type" data-type="2" value="2" @if($orgInfo && $orgInfo->org_type == 2) checked @endif @if($orgInfo && $orgInfo->state == 1)disabled @endif/>公司</p>
                                    </div>
                                </li>
                                <li class="companyName comp" @if($orgInfo && $orgInfo->org_type == 0) style="display: none" @endif>
                                    <em>公司名字</em>
                                    <div class="inline"><input type="text" name="org_name" value="@if($orgInfo){{$orgInfo->org_name}}@endif" @if($orgInfo && $orgInfo->state == 1)disabled @endif/><em class="compn_error error"></em></div>
                                </li>
                                <li class="companyDesc comp" @if($orgInfo && $orgInfo->org_type == 0) style="display: none" @endif>
                                    <em>公司简介</em>
                                    <div class="inline"><textarea name="org_desc" @if($orgInfo && $orgInfo->state == 1)disabled @endif>@if($orgInfo){{$orgInfo->org_desc}}@endif</textarea><em class="compd_error error"></em></div>
                                </li>
                                <li class="personDesc" style="display: none;">
                                    <em>个人简介</em>
                                    <div class="inline">
                                        <textarea name="people_desc" @if($orgInfo && $orgInfo->state == 1)disabled @endif></textarea>
                                        <em class="personDesc_error error"></em>
                                    </div>
                                </li>
                                <li class="areas">
                                    <em>所在地区</em>
                                    <div class="distruct">
                                        <select id="o_province" name="o_province" @if($orgInfo && $orgInfo->state == 1)disabled @endif></select>  
                                        <select id="o_city" name="o_city" @if($orgInfo && $orgInfo->state == 1)disabled @endif></select>  
                                        <select id="o_county" name="o_county" @if($orgInfo && $orgInfo->state == 1)disabled @endif></select>
                                        @if($orgInfo && $orgInfo->province && $orgInfo->city && $orgInfo->area)<script>opt1 = ["{{$orgInfo->province}}","{{$orgInfo->city}}","{{$orgInfo->area}}"]</script>@endif
                                        <script type="text/javascript">_init_area2();</script>
                                    </div>
                                </li>
                                <li class="trade">
                                    <em>行业经验</em>
                                    <div class="inline">
                                        <select class="exper" name="experience" @if($orgInfo && $orgInfo->state == 1)disabled @endif>
                                            <option value="1" @if($orgInfo && $orgInfo->experience == 1)selected @endif>1年</option>
                                            <option value="2" @if($orgInfo && $orgInfo->experience == 2)selected @endif>2年</option>
                                            <option value="3" @if($orgInfo && $orgInfo->experience == 3)selected @endif>3年</option>
                                            <option value="4" @if($orgInfo && $orgInfo->experience == 4)selected @endif>4年</option>
                                            <option value="5" @if($orgInfo && $orgInfo->experience == 5)selected @endif>5年</option>
                                            <option value="10" @if($orgInfo && $orgInfo->experience == 10)selected @endif>10年以上</option>
                                        </select>
                                    </div>
                                    <em class="trade_error error"></em>
                                </li>
                                <li  class="fields">
                                    <em>擅长领域</em>
                                    <div class="inline">
                                        {{--<select name="field" @if($orgInfo && $orgInfo->state == 1)disabled @endif>--}}
                                            {{--@foreach($fields as $field)--}}
                                            {{--<option value="{{$field->id}}" @if($orgInfo && $orgInfo['field'][0] == $field->id) selected @endif>{{$field->field}}</option>--}}
                                            {{--@endforeach--}}
                                        {{--</select>--}}
                                        @foreach($fields as $field)
                                            <input name="field" type="checkbox" value="{{$field->id}}" @if($orgInfo && in_array($field->id,$orgInfo['field'])) checked @endif/>{{$field->field}}
                                        @endforeach
                                    </div>
                                </li>
                                <li  class="skills">
                                    <em>开发技能</em>
                                    <div class="inline">
                                        {{--<select name="skill" @if($orgInfo && $orgInfo->state == 1)disabled @endif>--}}
                                            {{--@foreach($skills as $skill)--}}
                                                {{--<option value="{{$skill->id}}" @if($orgInfo && $orgInfo['skill'][0] == $skill->id) selected @endif>{{$skill->skill}}</option>--}}
                                            {{--@endforeach--}}
                                        {{--</select>--}}
                                        @foreach($skills as $skill)
                                            <input name="skill" type="checkbox" value="{{$skill->id}}" @if($orgInfo && in_array($skill->id,$orgInfo['skill'])) checked @endif/>{{$skill->skill}}
                                        @endforeach
                                    </div>
                                </li>
                                <li class="invoice">
                                    <em>发票情况</em>
                                    <div class="inline">
                                        <select name="has_invoice" @if($orgInfo && $orgInfo->state == 1)disabled @endif>
                                            <option value="0" @if($orgInfo && $orgInfo->has_invoice == 0) selected @endif>不能开发票</option>
                                            <option value="1" @if($orgInfo && $orgInfo->has_invoice == 1) selected @endif>开发票</option>
                                        </select>
                                    </div>
                                </li>
                                <li class="peoples comp" @if($orgInfo && $orgInfo->org_type == 0) style="display: none" @endif>
                                    <em>公司人数</em>
                                    <div class="inline"><input type="text" name="team_num" value=" @if($orgInfo){{$orgInfo->team_num}}@endif" @if($orgInfo && $orgInfo->state == 1)disabled @endif><em class="peoples_error error"></em></div>
                                </li>
                                <li class="plan">
                                    <em>解决方案</em>
                                    <div class="inline"><textarea name="solution" @if($orgInfo && $orgInfo->state == 1)disabled @endif> @if($orgInfo){{$orgInfo->solution}}@endif</textarea><em class="plan_error error"></em></div>
                                </li>
                                <li class="service">
                                    <em>附加服务</em>
                                    <div class="inline"><input type="text" name="other_service" value="{{$orgInfo?$orgInfo->other_service:''}}" @if($orgInfo && $orgInfo->state == 1)disabled @endif/><em class="service_error error"></em></div>
                                </li>
                                <li>
                                    <button @if($orgInfo && $orgInfo->state == 1)disabled @endif>提交审核</button>
                                </li>
                            </ul>
                            </form>
                        </div>

                        <!--案例管理-->
                        <div class="example" style="display: none">
                            <div class="addExample">
                                <p class="add">添加案例展示</p>
                                <div class="uploadExample">
                                    <ul>
                                        <form id="setExamInfo">
                                        <li><a href="javascript:void(0)" id="upExampleImg"><img id="target" src="{{url('images/upload_2.jpg')}}" style="width: 460px;height:300px" /></a><input type="hidden" id="examImgId" name="exam_id" value="" /><input type="hidden" name="org_id" value="{{$orgInfo?$orgInfo->id:''}}" /></li>
                                        <li class="exampleTitle"><em>案例标题</em><input type="text" name="title"/><em class="titleError error" style="display: none">必填</em></li>
                                        <li class="exampleDesc"><em>案例简述</em><textarea name="desc"></textarea><em class="descError error" style="display: none">必填</em></li>
                                        <li class="exampleLink"><em>案例链接</em><input type="text" name="url" /><em class="linkError error" style="display: none">必填</em></li>
                                        <li><button class="save" data-index="0">保存</button><button class="clear">取消</button></li>
                                        </form>
                                    </ul>
                                </div>
                            </div>
                            <div class="content">
                                @if($examInfos)
                                @foreach($examInfos as $examInfo)
                                <div id="e{{$examInfo->id}}" data-index="{{$examInfo->id}}">
                                    <dl>
                                        <dt><a href="#"><img id="exam_img" src="{{route('Api.ExamImg.Show',['id'=>$examInfo->id])}}" /></a></dt>
                                        <dd>
                                            <p><span class="btnBox"><button class="remove" data-index="{{$examInfo->id}}">删除</button><button class="edit" data-index="{{$examInfo->id}}">编辑</button></span><a href="#" id="exam_title">[{{$examInfo->title}}]</a></p>
                                            <p class="desc" id="exam_desc">
                                                {{\App\Services\TextStr::strMiddleReduceWordSensitive($examInfo->org_desc,10,'...')}}
                                            </p>
                                            <a href="#" class="links" id="exam_url">{{$examInfo->url}}</a>
                                        </dd>
                                    </dl>
                                </div>
                                    @endforeach
                                    @endif
                            </div>
                        </div>
                    </div>
                </div>

                <!--我是推广员-->
                <div class="chunks c_4" style="display:none;">
                    <!--当没认证为推广员时出现-->

                    <div class="authentication"   @if($facInfo && $facInfo->state == '0')style="display:block;" @else style="display:none;" @endif>
                        <p>您还没有进行推广员认证哦，赶紧认证吧~</p>
                        <button id="goPop">现在认证</button>
                    </div>

                    <div class="inviteCode" @if(!$facInfo || ($facInfo && $facInfo->state == '0')) style="display:none;" @else style="display:block;" @endif>
                        <ul>
                            <li class="selected">我的邀请码</li>
                            <li>我的团队</li>
                        </ul>
                        <div>
                            <p>我的邀请码： <em>{{$facInfo?$facInfo->invite_num:'无'}}</em></p>
                            <p class="desc"><em>Tips</em>邀请码是您作为推荐导师的身份标识，在邀请成员时，记得让成员填写完善哦，这样您才能获得成员
                                给您带来的丰富收益。</p>
                            @foreach($parent as $p)
                            <p>我的导师：<em>{{$p->realname}} {{$p->telephone}}</em></p>
                                @endforeach
                        </div>
                        <div class="team" style="display:none;">
                            <span><em class="name bold">姓名</em><em class="phone bold">联系方式</em><em class="city bold">地区</em><em class="money bold">累积收益/人</em></span>
                            <table>
                                <tr>
                                    @if($childs)
                                        @foreach($childs as $child)

                                    <td class="name bold">{{$child->realname}}</td>
                                    <td class="phone">{{$child->telephone}}</td>
                                    <td class="city">{{$child->province}}{{$child->city}}</td>
                                    <td class="money moneyTd">{{$child->rewards}}</td>
                                        @endforeach
                                        @endif
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </main>
    <script type="text/javascript">
        var setFacInfoUrl = "{{route('Api.Fac.setUserInfo')}}";
        var setOrgInfoUrl = "{{route('Api.Org.setOrgInfo')}}";
        var imgUrl = "{{route('Api.GetImage.Image',['id'=>''])}}";
        var modelImg = "{{url('images/upload_2.jpg')}}";
        var delExamInfo = "{{route('Api.Exam.delExampleInfo')}}";
        var setExamInfoUrl = "{{route('Api.Exam.setExampleInfo',['id'=>''])}}";
        var getExamInfoUrl = "{{route('Api.Exam.getExampleInfo')}}";
        var checkPop = "{{route('Home.Service.createPop')}}";

        $(document).ready(function(){
            $('#email').autoMail({
                emails:['qq.com','163.com','126.com','sina.com','sohu.com','yahoo.cn','gmail.com','hotmail.com','live.cn']
            });
        });
    </script>
    <script>
        jQuery(function($) {
            var doc = document,
                    $doc = $(doc);
            $doc.on('click','#goFac',function(){
                window.location.href='{{route('Home.Service.createFacilitator')}}';
            });
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'inputImage',
                url: '{{url('api/upload/image')}}',

                chunk_size: '20mb',
                filters: {
                    max_file_size: '10mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ],
                    prevent_duplicates: false
                },
                multi_selection: true,
                unique_names: true,

                flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
                silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

                file_data_name: 'photo',
                headers: {
                    Accept: 'application/json'
                },

                multipart_params: {
                    _token: '{{ csrf_token() }}'
                },

                init: {
                    PostInit: function () {
                    },

                    FilesAdded: function (up, files) {
                        up.start();
                    },

                    BeforeUpload: function (up, file) {
                        up.settings.multipart_params.file_name = file.name;
                    },

                    UploadProgress: function (up, file) {

                    },

                    Error: function (up, err) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(err.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }

                        noty({
                            type: 'error',
                            text: err.message + ' ' + responseMessage,
                            timeout: 800
                        });
                    },

                    FileUploaded: function (up, file, info) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(info.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }
                        $.ajax({
                            type: "post",
                            url: '{{route('Api.Fac.setUserInfo')}}',
                            dataType: "json",
                            data: {'photo_id': responseObj.data.id},
                            success: function (obj) {
                                if (obj.level === "success") {
                                    var d = new Date();
                                    imageUrl = "{{route('Api.Photo.Show',['id'=>'.'])}}/" + obj.data.user_id + "?" + d.getTime();
                                    $('#photo_id').attr('src', imageUrl);
                                }
                            },
                            error: function (obj) {
                                var datajson = obj.responseJSON;
                                noty({text: datajson.message, type: datajson.level, timeout: 800});
                            }
                        });
                    }
                }
            });
            uploader.init();

            jQuery.ajaxSetup({
                case: false,
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });

            //写入数据

        });
            var uploader2 = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'uplogo',
                url: '{{url('api/upload/image')}}',

                chunk_size: '20mb',
                filters: {
                    max_file_size: '10mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ],
                    prevent_duplicates: false
                },
                multi_selection: true,
                unique_names: true,

                flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
                silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

                file_data_name: 'photo',
                headers: {
                    Accept: 'application/json'
                },

                multipart_params: {
                    _token: '{{ csrf_token() }}'
                },

                init: {
                    PostInit: function () {
                    },

                    FilesAdded: function (up, files) {
                        up.start();
                    },

                    BeforeUpload: function (up, file) {
                        up.settings.multipart_params.file_name = file.name;
                    },

                    UploadProgress: function (up, file) {

                    },

                    Error: function (up, err) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(err.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }

                        noty({
                            type: 'error',
                            text: err.message + ' ' + responseMessage,
                            timeout: 800
                        });
                    },

                    FileUploaded: function (up, file, info) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(info.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }

                        $.ajax({
                            type: "post",
                            url: '{{route('Api.Org.setOrgInfo')}}',
                            dataType: "json",
                            data: {'logo_id': responseObj.data.id},
                            success: function (obj) {
                                if (obj.level === "success") {
                                    var d = new Date();
                                    imageUrl = "{{route('Api.OrgPhoto.Show',['id'=>'.'])}}/" + {{$user->id}} + "?" + d.getTime();
                                    $('#logo_img').attr('src', imageUrl);
                                }
                            },
                            error: function (obj) {
                                var datajson = obj.responseJSON;
                                noty({text: datajson.message, type: datajson.level, timeout: 800});
                            }
                        });
                    }
                }
            });
            uploader2.init();

        /*  ------------------上传案例截图-------------*/
        var uploader4 = new plupload.Uploader({
            runtimes: 'html5,flash,silverlight,html4',
            browse_button: 'upExampleImg',
            url: '{{url('api/upload/image')}}',

            chunk_size: '20mb',
            filters: {
                max_file_size: '10mb',
                mime_types: [
                    {title: "Image files", extensions: "jpg,gif,png"}
                ],
                prevent_duplicates: false
            },
            multi_selection: true,
            unique_names: true,

            flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
            silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

            file_data_name: 'photo',
            headers: {
                Accept: 'application/json'
            },

            multipart_params: {
                _token: '{{ csrf_token() }}'
            },

            init: {
                PostInit: function () {
                },

                FilesAdded: function (up, files) {
                    up.start();
                },

                BeforeUpload: function (up, file) {
                    up.settings.multipart_params.file_name = file.name;
                },

                UploadProgress: function (up, file) {

                },

                Error: function (up, err) {
                    var responseObj = '', responseMessage = '';
                    try {
                        responseObj = $.parseJSON(err.response);
                        responseMessage = responseObj.message;
                    } catch ($e) {

                    }

                    noty({
                        type: 'error',
                        text: err.message + ' ' + responseMessage,
                        timeout: 800
                    });
                },

                FileUploaded: function (up, file, info) {
                    var responseObj = '', responseMessage = '';
                    try {
                        responseObj = $.parseJSON(info.response);
                        responseMessage = responseObj.message;
                    } catch ($e) {

                    }
                    var d = new Date();
                    var imageId = responseObj.data.id;
                    $('#examImgId').val(imageId);
                    imageUrl = "{{route('Api.GetImage.Image',['id'=>'.'])}}/" + imageId + "?" + d.getTime();
                    $('#target').attr('src', imageUrl);
                }
            }
        });
        uploader4.init();
    </script>
@endsection